// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/dwio/dwrf/common/common.h>
#include <pollux/common/compression/compression.h>

#include <melon/conv.h>

namespace kumo::pollux::dwrf {

std::string writerVersionToString(WriterVersion version) {
  switch (static_cast<int32_t>(version)) {
    case ORIGINAL:
      return "original";
    case DWRF_4_9:
      return "dwrf-4.9";
    case DWRF_5_0:
      return "dwrf-5.0";
    case DWRF_6_0:
      return "dwrf-6.0";
    case DWRF_7_0:
      return "dwrf-7.0";
  }
  return melon::to<std::string>("future - ", version);
}

std::string streamKindToString(StreamKind kind) {
  switch (static_cast<int32_t>(kind)) {
    case StreamKind_PRESENT:
      return "present";
    case StreamKind_DATA:
      return "data";
    case StreamKind_LENGTH:
      return "length";
    case StreamKind_DICTIONARY_DATA:
      return "dictionary";
    case StreamKind_DICTIONARY_COUNT:
      return "dictionary count";
    case StreamKind_NANO_DATA:
      return "nano data";
    case StreamKind_ROW_INDEX:
      return "index";
    case StreamKind_IN_DICTIONARY:
      return "in dictionary";
    case StreamKind_STRIDE_DICTIONARY:
      return "stride dictionary";
    case StreamKind_STRIDE_DICTIONARY_LENGTH:
      return "stride dictionary length";
    case StreamKind_BLOOM_FILTER_UTF8:
      return "bloom";
    case StreamKindOrc_PRESENT:
      return "orc present";
    case StreamKindOrc_DATA:
      return "orc data";
    case StreamKindOrc_LENGTH:
      return "orc length";
    case StreamKindOrc_DICTIONARY_DATA:
      return "orc dictionary";
    case StreamKindOrc_DICTIONARY_COUNT:
      return "orc dictionary count";
    case StreamKindOrc_SECONDARY:
      return "orc secondary";
    case StreamKindOrc_ROW_INDEX:
      return "orc index";
    case StreamKindOrc_BLOOM_FILTER:
      return "orc bloom";
    case StreamKindOrc_BLOOM_FILTER_UTF8:
      return "orc bloom utf8";
    case StreamKindOrc_ENCRYPTED_INDEX:
      return "orc encrypted index";
    case StreamKindOrc_ENCRYPTED_DATA:
      return "orc encrypted data";
    case StreamKindOrc_STRIPE_STATISTICS:
      return "orc stripe statistics";
    case StreamKindOrc_FILE_STATISTICS:
      return "orc file statistics";
  }
  return melon::to<std::string>("unknown - ", kind);
}

std::string columnEncodingKindToString(ColumnEncodingKind kind) {
  switch (static_cast<int32_t>(kind)) {
    case ColumnEncodingKind_DIRECT:
      return "direct";
    case ColumnEncodingKind_DICTIONARY:
      return "dictionary";
    case ColumnEncodingKind_DIRECT_V2:
      return "direct rle2";
    case ColumnEncodingKind_DICTIONARY_V2:
      return "dictionary rle2";
  }
  return melon::to<std::string>("unknown - ", kind);
}

DwrfStreamIdentifier EncodingKey::forKind(const proto::Stream_Kind kind) const {
  return DwrfStreamIdentifier(node_, sequence_, 0, kind);
}

DwrfStreamIdentifier EncodingKey::forKind(
    const proto::orc::Stream_Kind kind) const {
  return DwrfStreamIdentifier(node_, sequence_, 0, kind);
}

} // namespace kumo::pollux::dwrf
